#include "gamemap.hpp"
#include "path_cost_calculators.hpp"
#include "terrain.hpp"
#include "tile.hpp"

road_cost_calculator::road_cost_calculator(const hex::gamemap& m) : map_(m)
{}

int road_cost_calculator::movement_cost(const hex::location& a, const hex::location& b) const
{
	const hex::const_tile_ptr t1 = map_.get_tile(a);
	const hex::const_tile_ptr t2 = map_.get_tile(b);
	if(t1->terrain()->move_cost() < 0 || t2->terrain()->move_cost() < 0) {
		return -1;
	}

	return t1->terrain()->move_cost() + t2->terrain()->move_cost();
}

int road_cost_calculator::estimated_cost(const hex::location& a, const hex::location& b) const
{
	return hex::distance_between(a, b)*20;
}

bool road_cost_calculator::allowed_to_move(const hex::location& a) const
{
	if(map_.is_loc_on_map(a) == false) {
		return false;
	}

	return map_.get_tile(a)->terrain()->move_cost() >= 0;
}

move_cost_calculator::move_cost_calculator(const hex::gamemap& m) : map_(m)
{}

int move_cost_calculator::movement_cost(const hex::location& a, const hex::location& b) const
{
	const hex::const_tile_ptr t2 = map_.get_tile(b);
	if(t2->terrain()->move_cost() < 0) {
		return -1;
	}

	if(t2->road(get_adjacent_direction(b, a))) {
		return 5;
	}

	return t2->terrain()->move_cost();
}

int move_cost_calculator::estimated_cost(const hex::location& a, const hex::location& b) const
{
	return hex::distance_between(a, b)*20;
}

bool move_cost_calculator::allowed_to_move(const hex::location& a) const
{
	if(map_.is_loc_on_map(a) == false) {
		return false;
	}

	return map_.get_tile(a)->terrain()->move_cost() >= 0;
}
